package bishi.day10_4_28;

/**
 * @author 是阿秋啊
 * @date 2022/04/28 17:42
 **/
public class jing_zi_qi {
    public static void main(String[] args) {
        int[][] arr = {{1,0,1},{1,-1,-1},{1,-1,0}};
        System.out.println(checkWon(arr));
    }
    public static boolean checkWon(int[][] board) {
        // write code here
        int r = board.length;
        int c = board[0].length;
        for(int i = 0; i < c; i++) {
            if(board[0][i] == 1){
                if(helper(board,0,i)) {
                    return true;
                }
            }
        }
        for(int i = 1; i < r; i++) {
            if(board[i][0] == 1){
                if(helper(board,i,0)) {
                    return true;
                }
            }
        }
        return false;
    }
    public static boolean helper(int[][] arr,int i,int j) {
        boolean heng = true;
        boolean shu = true;
        boolean zheng = true;
        boolean fan = true;
        if(i ==0 && j == arr[0].length - 1) {
            for(int k = 0; k < arr.length; k++) {
                for(int m = j; m >= 0; m--) {
                    if(m + k == j) {
                        if(arr[k][m] != 1) {
                            fan = false;
                            break;
                        }
                    }
                }
                if(!fan) {
                    break;
                }
            }
        }else {
            fan = false;
        }
        if(i == 0 && j == 0) {
            for(int k = 0; k < arr.length; k++) {
                for(int m = j; m <= arr[0].length; m++) {
                    if(m == k) {
                        if(arr[k][m] != 1) {
                            zheng = false;
                            break;
                        }
                    }
                }
                if(!zheng) {
                    break;
                }
            }
        }else {
            zheng = false;
        }
        for(int k = 0; k < arr[0].length;k++) {
            if(arr[i][k] != 1) {
                heng = false;
                break;
            }
        }
        for(int k = 0; k < arr[0].length;k++) {
            if(arr[k][j] != 1) {
                shu = false;
                break;
            }
        }
        return heng || shu || zheng || fan;
    }
}